import axios from 'axios';
import sha1 from 'sha1';
const getSign = (params = {}) => {
  var sortObj = Object.keys(params).sort();
  console.log(sortObj);
  var str = '';
  for (var i = 0; i < sortObj.length; i++) {
    str += sortObj[i] + (typeof (params[sortObj[i]]) === 'string' ? params[sortObj[i]] : JSON.stringify(params[sortObj[i]]));
  };
  return sha1('f13f8f79ba548c4357fee7e62680225b' + str + 'f13f8f79ba548c4357fee7e62680225b').toUpperCase();
};
const postData = (method = '', para = {}) => {
  var params = {
    'appKey': '89d3a861d58f8d3e9cbe6e4ed74d71c4',
    'timestamp': (new Date()).getTime(),
    'v': '1.0',
    'method': method,
    'entityId': '00289918',
    'filterAccMake': false
  };
  para = para || {};
  for (var key in para) {
    params[key] = para[key];
  };
  params['sign'] = getSign(params);
  return axios({
    method: 'post',
    url: 'http://open.2dfire.com/router',
    params: params
  });
};
// 获取分类
export const sGetKinds = (para = {}) => {
  return postData('dfire.thirdpart.wm.menu.query', para);
};
// 获取菜单
export const sGetMenus = (para = {}) => {
  return postData('dfire.thirdpart.wm.menu.query', para);
};
// 提交订单
export const sSubmitOrder = (para = {}) => {
  return postData('dfire.thirdpart.wm.order.submit', para);
};
// 提交是否成功
export const sCheckOrderOk = (para = {}) => {
  return postData('dfire.thirdpart.wm.order.confirm', para);
};
// 获取订单
export const sGetOrderList = (para = {}) => {
  return postData('dfire.shop.order.list', para);
};
// 获取订单详细
export const sGetOrderDetail = (para = {}) => {
  return postData('dfire.shop.order.instance.list', para);
};

// 取消订单
export const sCancelOrder = (para = {}) => {
  return postData('dfire.thirdpart.wm.order.cancel', para);
};

// 商家信息
export const sGetSellList = (para = {}) => {
   return axios({
    method: 'get',
    url: 'static/data.json'
  });
};
